﻿using FDSimpleModelGenerator.Common.Enums;
using FDSimpleModelGenerator.IServices;

namespace FDSimpleModelGenerator.Services.Mappers
{
    /// <summary>
    /// jdbc mybatis类型转化服务
    /// </summary>
    public class JdbcTypeDataTypeMapperService : IDataTypeMapperService
    {
        public LanguageDataType LanguageDataType => LanguageDataType.JdbcType;

        public string Map(string dbType, bool isUnsigned = false)
        {
            dbType = dbType.ToLower();
            var res = dbType;
            switch (dbType)
            {
                case "int":
                case "integer":
                case "serial":
                case "smallint":
                case "tinyint":
                case "smallserial":
                    res = "integer";
                    break;
                case "text":
                case "clob":
                    res = "clob";
                    break;
                case "double":
                case "number":
                case "decimal":
                case "real":
                case "money":
                case "double precision":
                case "smallmoney":
                    res = "double";
                    break;
                case "long varchar":
                    res = "longvarchar";
                    break;
                case "datetime":
                case "timestamp":
                case "datetime2":
                case "smalldatetime":
                    res = "timestamp";
                    break;
                case "bit":
                    res = "boolean";
                    break;
                case "bigserial":
                    res = "bigint";
                    break;
            }

            return res.ToUpper();
        }
    }
}
